package com.wu.components;

import com.wu.flandre_common.entity.RpcRequest;
import com.wu.flandre_common.entity.RpcResponse;
import com.wu.flandre_common.property.Constants;
import com.wu.flandre_common.util.RpcRestTemp;
import com.wu.handler.EngineMailHandler;
import com.wu.handler.EngineStateHandler;
import io.netty.channel.ChannelHandlerContext;

/**
 * EventDispacher <br/>
 *
 * @author 50816 <br/>
 * @date 2019/12/22 17:16 <br/>
 */
public class EventDispacher {

    public RpcResponse dispache(ChannelHandlerContext ctx, RpcRequest request) {
        RpcResponse<?> response = null;
        Integer eventId = request.getId();

        EngineStateHandler stateHandler = new EngineStateHandler();
        switch (eventId) {
            case Constants.ENGINE_MAIL:
                EngineMailHandler mailHandler = new EngineMailHandler();
                response= mailHandler.verificationCode(request);
                break;
            case Constants.ENGINE_START:
                response = stateHandler.start();
                break;
            case Constants.ENGINE_RESTART:
                response = stateHandler.restart();
                break;
            case Constants.ENGINE_STOP:
                response = stateHandler.stop();
                break;
            default:
                response = RpcRestTemp.error("未知事件ID,数据被丢弃");
                break;
        }
        return response;
    }
}
